package com.nbf.Collections;

import java.util.HashMap;
import java.util.Map;

/** Container for MarketVariables<br>
 * Typically one of these exists for each date entry for all of a symbol's active dates.<br>
 * It is backed by a HashMap
 * 
 * @author Zachary David
 *
 */
public class DataPack
{
	private Map<MarketVariable,MarketVariable> _variables = new HashMap<MarketVariable,MarketVariable>();
	
	public DataPack()
	{
		
	}
	
	/** Calls the backing HashMap's containsKey method
	 * 
	 * @param name
	 * @return if there is a market variable with the corresponding name
	 */
	public boolean contains(String name)
	{
		return _variables.containsKey(name);
	}
	
	/** Only adds if a MarketVariable of the same name does not already exist.
	 *  This is to prevent variable collisions between files.
	 * @param name Name of MarketVariable
	 * @param value Value of MarketVariable
	 * @return whether it was successfully added
	 */
	public boolean tryAdd(String name, Double value)
	{
		if(!_variables.containsKey(name))
		{
			MarketVariable mv = new MarketVariable(name, value);
			_variables.put(mv,mv);
			return true;
		}
		
		return false;
	}
	
	public Double tryGet(String name)
	{
		MarketVariable mv = _variables.get(name);
		if(mv == null)
			return null;
		return mv.getValue();
	}
}
